import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

//所有页面路由
import systemRouter from './modules/system'
import consumerRouter from './modules/consumer'
import couponRouter from './modules/coupon'
import commodityRouter from './modules/commodity'
import blindboxRouter from './modules/blindbox'
// 订单
import orderRouter from './modules/order'
import marketingRouter from './modules/marketing'

/* Router Modules */

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 背包发货
  {
    path: '/invoice',
    component: Layout,
    redirect: '/invoice/invoicelist',
    name: 'Invoice',
    meta: {
      title: 'invoice',
      icon: 'component',
      roles: ['other'] // you can set roles in root nav
    },
    children: [
      {
        path: 'invoicelist',
        component: () => import('@/views/invoice/invoiceList'),
        name: 'InvoiceList',
        meta: {
          title: 'invoicelist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'invoicedetail',
        component: () => import('@/views/invoice/invoiceDetail'),
        name: 'InvoiceDetail',
        hidden: true,
        meta: {
          title: 'invoicedetail',
          roles: ['other'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  // 用户管理
  consumerRouter,
  // 赏袋
  marketingRouter,
  // 盲盒
  blindboxRouter,
  // 优惠券
  couponRouter,

  {
    path: '/product',
    component: Layout,
    redirect: '/product/productlist',
    name: 'Product',
    meta: {
      title: 'product',
      icon: 'star',
      roles: ['other']
    },
    children: [
      {
        path: 'productcategory',
        component: () => import('@/views/product/productCategory'),
        name: 'ProductCategory',
        meta: {
          title: 'Productcategory',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'productlist',
        component: () => import('@/views/product/productList'),
        name: 'PropductList',
        meta: {
          title: 'productlist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },]
  },
  // 商城
  commodityRouter,
  //合成列表
  {
    path: '/synthesis',
    component: Layout,
    redirect: '/synthesis/synthesislist',
    name: ' Synthesis',
    meta: {
      title: 'synthesis',
      icon: 'example',
      roles: ['other'] // you can set roles in root nav
    },
    children: [
      {
        path: 'synthesislist',
        component: () => import('@/views/synthesis/synthesisList'),
        name: 'SynthesisList',
        meta: {
          title: 'synthesislist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  orderRouter,
  // 战令列表
  {
    path: '/war',
    component: Layout,
    redirect: '/war/warlist',
    name: 'War',
    meta: {
      title: 'war',
      icon: 'education',
      roles: ['other'] // you can set roles in root nav
    },
    children: [
      {
        path: 'warlist',
        component: () => import('@/views/war/warList'),
        name: 'WarList',
        meta: {
          title: 'warlist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'warset',
        component: () => import('@/views/war/warSet'),
        name: 'WarSet',
        meta: {
          title: 'warset',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      // {
      //   path: 'kind',
      //   component: () => import('@/views/war/kindList.vue'),
      //   name: 'Kind',
      //   meta: {
      //     title: '王者奖项设置',
      //     roles: ['other'] // or you can only set roles in sub nav
      //   }
      // },
      // {
      //   path: 'blind',
      //   component: () => import('@/views/war/blindList.vue'),
      //   name: 'Blind',
      //   meta: {
      //     title: '能量球等级奖品设署',
      //     roles: ['other'] // or you can only set roles in sub nav
      //   }
      // },
    ]
  },
  // 能量球
  {
    path: '/blind',
    component: Layout,
    redirect: '/blind/blindlist',
    name: 'Blind',
    meta: {
      title: '能量球管理',
      icon: 'education',
      roles: ['other'] // you can set roles in root nav
    },
    children: [
      {
        path: 'kindlist',
        component: () => import('@/views/enery/kindList.vue'),
        name: 'KindList',
        meta: {
          title: '王者奖项设置',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'blindlist',
        component: () => import('@/views/enery/blindList.vue'),
        name: 'BlindList',
        meta: {
          title: '能量球等级奖品设署',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
    ]
  },
  // 商城交易列表
  {
    path: '/transition',
    component: Layout,
    redirect: '/transition/transitionlist',
    name: 'Transition',
    meta: {
      title: 'transition',
      icon: 'education',
      roles: ['other'] // you can set roles in root nav
    },
    children: [
      {
        path: 'transitionlist',
        component: () => import('@/views/transition/transitionList'),
        name: 'TransitionList',
        meta: {
          title: 'transitionlist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'cashlist',
        component: () => import('@/views/transition/cashList'),
        name: 'CashList',
        meta: {
          title: 'cashlist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'transitionsquarelist',
        component: () => import('@/views/transition/transitionsquarelist'),
        name: 'TransitionSquareList',
        meta: {
          title: 'transitionsquarelist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  // 运费规则列表
  {
    path: '/freight',
    component: Layout,
    redirect: '/freight/freightlist',
    name: ' Freight',
    meta: {
      title: 'freight',
      icon: 'tree',
      roles: ['other'] // you can set roles in root nav
    },
    children: [
      {
        path: 'freightlist',
        component: () => import('@/views/freight/freightList'),
        name: 'FreightList',
        meta: {
          title: 'freightlist',
          roles: ['other'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  // 系统设置
  systemRouter,

  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'errorPages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/error-page/401'),
  //       name: 'Page401',
  //       meta: { title: 'page401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/error-page/404'),
  //       name: 'Page404',
  //       meta: { title: 'page404', noCache: true }
  //     }
  //   ]
  // },
  // 先藏着说不定有用
  // {
  //   path: '/theme',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/theme/index'),
  //       name: 'Theme',
  //       meta: { title: 'theme', icon: 'theme' }
  //     }
  //   ]
  // },

  // {
  //   path: '/i18n',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/i18n-demo/index'),
  //       name: 'I18n',
  //       meta: { title: 'i18n', icon: 'international' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://github.com/PanJiaChen/vue-element-admin',
  //       meta: { title: 'externalLink', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  base: '/Management',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
